<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2023-09-04 13:57:31
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description:   检验单:gridOps="gridOptions" other
-->
<template>
  <sc-VxeTable
    ref="xGrid"
    :gridEvts="gridEvents"
    :tablecode="'pro_process_inspect'"
    :url="api.pro.inspect.list"
  >
  </sc-VxeTable>
  <pack
    v-if="packDlg"
    ref="packRef"
    @success="handleSuccess"
    @closed="packDlg = false"
  ></pack>
  <SaveStyle
    v-if="saveStyleDlg"
    ref="saveStyle"
    @success="handleSuccess"
    @closed="saveStyleDlg = false"
  >
  </SaveStyle>
  <SaveBarcode
    v-if="saveBarcodeDlg"
    ref="saveBarcode"
    @success="handleSuccess"
    @closed="saveBarcodeDlg = false"
    />
</template>
<script>
import pack from "./pack";
import SaveStyle from "./../../market/customer/storage/savestyle.vue";
import SaveBarcode from "./../../market/customer/storage/savebarcode.vue";
export default {
  name: "pro_process_inspect",
};
</script>
<script setup>
import { ref, nextTick } from "vue";
import api from "@/api";
// , onMounted, reactive, ref
// const router = useRouter();
const packDlg = ref(false);
const saveStyleDlg = ref(false);
const saveBarcodeDlg = ref(false);
const xGrid = ref({});
const packRef = ref({});
const saveStyle = ref({});
const saveBarcode = ref(null);

const handleSuccess = () => {
  xGrid.value.refresh();
};
const gridEvents = {
  pack: ({ button }) => {
    packDlg.value = true;
    nextTick(() => {
      packRef.value.setData(button.selectRecords[0]).open();
    });
  },
  setStyle: ({ button }) => {
    saveStyleDlg.value = true;
    nextTick(() => {
      api.market.customerStorage.list
        .get({
          filter: [
            { id: { type: "in", value: button.selectRecords.map(v => v.order_id) } },
          ],
        })
        .then(v => {
          if (v.code == 200) saveStyle.value.open().setData(v.data.rows);
        });
    });
  },
  setBarcode: ({ button }) => {
    saveBarcodeDlg.value = true;
    nextTick(() => {
      saveBarcode.value.open().setData(button.selectRecords.map(v => {
        return {id: v.order_id}
      }));
    });
  }
};
</script>
